/* eslint-disable camelcase */
<template>
  <div class="search-result">
    <van-list v-model="isloading" :finished="finished" finished-text="没有更多了" @load="onload">
     <ArticleItem  v-for="(item, i) in list" :key="i" :item="item" class="result_item"></ArticleItem>
    </van-list>
  </div>
</template>

<script>
import { getsearchResult } from '@/api/search'
import ArticleItem from '@/components/article'
export default {
  name: 'search-result',
  components: { ArticleItem },
  props: {
    kw: {
      type: String,
      required: true
    }
  },
  data () {
    return {
      isloading: false,
      finished: false,
      list: [],
      page: 1
    }
  },
  methods: {
    async onload () {
      // eslint-disable-next-line camelcase
      const { results } = await getsearchResult({
        page: this.page,
        per_page: 20,
        q: this.kw
      })
      this.list.push(...results)
      this.page++
      this.isloading = false

      if (results.length <= 0) {
        this.finished = true
      }
    }
  }
}
</script>

<style lang="scss" scoped>
  .search-result{
    .result_item {
      margin-bottom: 10px;
    }
  }
</style>
